888F - Connecting Vertices - CodeForces Solution


dp graphs *2500

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;
const int p=1000000007;

int f[600][600],g[600][600],h[600][600];
int i,j,k,n;

int main()
{
	cin>>n;
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			cin>>g[i][j];
	for (i=1;i<=n;i++)
		f[i][i]=1;
	for (i=1;i<n;i++)
		for (j=1;i+j<=n;j++)
		{
			for (k=j;k<=i+j;k++)
				f[j][i+j]=(f[j][i+j]+1LL*f[j][k]*h[k][i+j])%p;
			if (g[j][i+j])
				for (k=j;k<i+j;k++)
					h[j][i+j]=(h[j][i+j]+1LL*f[j][k]*f[k+1][i+j])%p;
			f[j][i+j]=(f[j][i+j]+h[j][i+j])%p;
		}
	cout<<f[1][n];
}


Comments

Submit
0 Comments
More Questions

1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams
1369B - AccurateLee
892B - Wrath
999A - Mishka and Contest
727C - Guess the Array
1625C - Road Optimization
1715D - 2+ doors
267A - Subtractions